/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2014.09.24                                          *
 * Description:      geom point of dim = FREEMAPS_DIM                    *
 * Acknowledgements: This file is a copy from libMesh projection         *
 *                   with slight modification.                           *
 *                                                                       *
 *************************************************************************/
#if 0
namespace FreeMAPs
{

inline
Point::Point (
    const double x,
    const double y,
    const double z)
{
    d_coords.resize (3);
    d_coords [0] = x;
    d_coords [1] = y;
    d_coords [2] = z;
}


inline
Point::~Point()
{}


inline void
Point::create(
    const double x,
    const double y,
    const double z)
{
    d_coords.resize (3);
    d_coords [0] = x;
    d_coords [1] = y;
    d_coords [2] = z;
}


inline void
Point::create (
    const double* p,
    const int dim)
{
    FREEMAPS_ASSERT_LE (dim, FREEMAPS_DIM);

    for (int i = 0; i < dim; ++i)
    {
        d_coords [i] = p[i];
    }
}


inline void
Point::create(
    const std::map<std::string, double>& m,
    const int dim)
{
    FREEMAPS_ASSERT_LE (dim, FREEMAPS_DIM);

    std::map<std::string, double>::const_iterator find_x = m.find ("r.x");
    FREEMAPS_ASSERT (find_x != m.end());
    d_coords [0] = find_x->second;

    if (dim > 1)
    {
        std::map<std::string, double>::const_iterator find_y = m.find ("r.y");
        FREEMAPS_ASSERT (find_y != m.end());
        d_coords [1] = find_y->second;
    }

    if (dim > 2)
    {
        std::map<std::string, double>::const_iterator find_z = m.find ("r.z");
        FREEMAPS_ASSERT (find_z != m.end());
        d_coords [2] = find_z->second;
    }
}


inline void
Point::create (
    const std::vector<double>& p)
{
    /*const*/ int dim = static_cast<int>(p.size());
    FREEMAPS_ASSERT_LE (dim, FREEMAPS_DIM);

    //maybe dim > 3, have error
    if(dim > 3)
    {
        dim = 3;
    }

    for (int i = 0; i < dim; ++i)
    {
        d_coords [i] = p[i];
    }
}


inline void
Point::clear()
{
    d_coords.resize (3, 0.);
}


inline double
Point::operator [](
    const int i)const
{
    return d_coords [i];
}


inline double&
Point::operator [](
    const int i)
{
    return d_coords [i];
}


inline double
Point::operator ()(
    const int i)const
{
    return d_coords [i];
}


inline double&
Point::operator ()(
    const int i)
{
    return d_coords [i];
}


inline bool
PointCmp::operator()(
    const Point& lhs,
    const Point& rhs) const
{
    if (!MathUtilities<double>::equal_eps (lhs (0), rhs (0)))
    {
        return (lhs (0) < rhs (0));
    }
    else if (!MathUtilities<double>::equal_eps (lhs (1), rhs (1)))
    {
        return (lhs (1) < rhs (1));
    }
    else if (!MathUtilities<double>::equal_eps (lhs (2), rhs (2)))
    {
        return (lhs (2) < rhs (2));
    }
    else
    {
        return false;
    }
}

}
#endif
